package cn.itcast.mq.bean.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class BeanRabbitBackupConfig {

    // 备份交换机名
    public static final String BACKUP_EXCHANGE = "backup.exchange";

    // 备份队列名称
    public static final String BACKUP_QUEUE = "backup.queue";
    // 报警队列名称
    public static final String WARNING_QUEUE = "warning.queue";

    @Bean
    public FanoutExchange backupExchange() {
        return new FanoutExchange(BACKUP_EXCHANGE);
    }

    @Bean
    public Queue backupQueue() {
        return QueueBuilder.durable(BACKUP_QUEUE).build();
    }

    @Bean
    public Queue warningQueue() {
        return QueueBuilder.durable(WARNING_QUEUE).build();
    }

    @Bean
    public Binding bindingBackupQueue(FanoutExchange backupExchange, Queue backupQueue) {
        return BindingBuilder.bind(backupQueue).to(backupExchange);
    }

    @Bean
    public Binding bindingWarningQueue(FanoutExchange backupExchange, Queue warningQueue) {
        return BindingBuilder.bind(warningQueue).to(backupExchange);
    }

}
